<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<%@ taglib prefix="memberForm" uri="http://www.tongxingzhe.cn/memberForm" %>

<!DOCTYPE html>
<html lang="zh">
<head>
<title>${subject == null ? '发布' : '编辑'}手机官网</title>
<%@include file="../include/commonFile.jsp" %>
<link rel="stylesheet" href="${ctx}/css/common/list.css">
<link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
	<%@include file="../include/sidebar.jsp"%>
	<!--内容-->
	<section>
		<div class="section-main">

			<!-- 正文请写在这里 -->
			<div class="add-form-content">
			<form id="myForm" class="layui-form mt20" method="post" action="${ctx}/subject/subject/save.do">
				<div class="layui-form-item">
					<label class="layui-form-label">所属合作商<span class="f-verify-red">*</span></label>
					<div class="layui-input-inline">
						<input type="hidden" name="memberId"			lay-verify="orgId"
							   value="${subject.memberId}"/>
						<input type="text" id="member_name" value="${memberForm:getRealNameById(subject.memberId)}" class="layui-input" readonly/>
					</div>
					<c:if test="${empty subject.id}">
						<a class="layui-btn layui-btn-danger" type="button"
						   onclick="openSelMemberDialog(this,'选择所属合作商','${ctx}/system/member/selectPartner.do','950px','570px')">
							选择
						</a>
					</c:if>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">名称<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="name" lay-verify="name"  autocomplete="off" placeholder="手机官网名称" class="layui-input" value="${subject.name}">
						<input type="hidden" name="id" value="${subject.id}"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">封面图<span class="f-verify-red">*</span></label>
					<div class="cover-content">
						<input type="hidden" name="picture" id="pic" lay-verify="pic" value="${subject.picture}" />
						<c:if test="${subject == null || empty subject.picture}">
							<span id="cover-img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
						</c:if>
						<c:if test="${subject != null && not empty subject.picture}">
							<span id="cover-img" class="cover-img" style="background-image:url('${subject.picture}')"></span>
						</c:if>
						<a class="layui-btn layui-btn-danger" id="sel_pic_img">+添加图片</a>
						<div class="form-word-aux">建议尺寸：800x450</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">排序号</label>
						<div class="layui-input-inline">
							<input type="text" name="sort" lay-verify="sort" autocomplete="off" class="layui-input" value="${subject.sort}" >
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">描述<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
				   		<textarea name="remarks" placeholder="手机官网描述" lay-verify="remarks" class="layui-textarea"  >${subject.remarks}</textarea>
				    </div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
				   		<a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
						<a href="${ctx}/subject/subject/subjectList.do" class="layui-btn layui-btn-primary">取消</a>
				  	</div>
				</div>
			</form>
			</div>
		</div><!--底部-->
		<%@include file="../include/footer.jsp" %>
		<c:if test="${not empty subject.memberId}">
			<c:set var="isExpire" value="${memberForm:isExpire(subject.memberId, null)}"/>
		</c:if>
	</section>
</div>
<script>
	$(function() {
        layui.use(['form'], function () {
            var form = layui.form, laydate = layui.laydate;

            //自定义验证规则
            form.verify({
                orgId: function (value) {
                    if(!value){
                        return "请选择所属合作商"
                    }
                    if ('${isExpire}' == 'true' && '${subject.id}' == '') {
                        return "当前合作商已到期，不能发布数据"
                    }
                },
                name : function(value) {
                    if (value == "") {
                        return '请填写手机官网名称';
                    }
                },
                pic : function(value) {
                    if (value == "") {
                        return "请上传手机官网封面图";
                    }
                },
                sort : function(value) {
                    if (!util.checkNumber(value)) {
                        return "请输入正确的数字";
                    }
                },
                remarks : function(value) {
                    if (value == "") {
                        return '请填写手机官网描述';
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                location.href = "${ctx}/subject/subject/subjectList.do";
                            });
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    });
                })
                return false;
            });
        });
        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.SUBJECT.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
	})
    function openSelMemberDialog(that, title, url, width, height) {
        txz.openDialogIframe({
            width: width,
            height: height,
            title: title,
            url: url,
            cb: function (opt) {
                var content = opt.content;
                if (content.doSubmit()) {
                    var data = content.returnData();
                    $('input[name=memberId]').val(data.id);
                    $('#member_name').val(data.name);
                    top.layer.close(opt.index);
                }
            }
        })
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '手机官网管理',
            href: '${ctx}/subject/subject/subjectList.do'
        },{
            name: '${subject == null ? '发布' : '编辑'}手机官网',
            curr: true
        }],
        btns:[{
            name: '返回',
            href: 'javascript:history.back();',
            icon: 'back'
        }]
    });
</script>
</body>
</html>